home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksslpkcs12.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.8 KB  |  195 lines

  1. /* This file is part of the KDE project
  2.  *
  3.  * Copyright (C) 2001 George Staikos <staikos@kde.org>
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public License
  16.  * along with this library; see the file COPYING.LIB.  If not, write to
  17.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19.  */
  20.  
  21. #ifndef _KSSLPKCS12_H
  22. #define _KSSLPKCS12_H
  23.  
  24. #ifdef Q_WS_WIN
  25. #include "ksslconfig_win.h"
  26. #else
  27. #include "ksslconfig.h"
  28. #endif
  29.  
  30. #ifdef KSSL_HAVE_SSL
  31. #define crypt _openssl_crypt
  32. #include <openssl/pkcs12.h>
  33. #undef crypt
  34. #else
  35. class PKCS12;
  36. class EVP_PKEY;
  37. class X509;
  38. #endif
  39.  
  40. #include <ksslcertificate.h>
  41. #include <ksslcertchain.h>
  42.  
  43. #ifndef STACK_OF
  44. #define STACK_OF(x) void
  45. #endif
  46.  
  47. class KSSL;
  48. class KSSLPKCS12Private;
  49. class KOpenSSLProxy;
  50.  
  51. /**
  52.  * KDE PKCS#12 Certificate
  53.  *
  54.  * As of yet, this class is being defined.  if you use it, let it be known
  55.  * that BC will break on you until this message is removed.
  56.  *
  57.  * @author George Staikos <staikos@kde.org>
  58.  * @see KSSL, KSSLCertificate
  59.  * @short KDE PKCS#12 Certificate
  60.  */
  61. class KIO_EXPORT KSSLPKCS12 {
  62. friend class KSSL;
  63.  
  64. public:
  65.     /**
  66.      *  Destroy this PKCS#12 certificate
  67.      */
  68.     virtual ~KSSLPKCS12();
  69.  
  70.     /**
  71.      *  The name of this certificate.  This can be used to refer to the
  72.      *  certificate instead of passing the object itself.
  73.      *  @return the name of the certificate
  74.      */
  75.     QString name();
  76.  
  77.     /**
  78.      *  Create a KSSLPKCS12 object from a Base64 in a QString.
  79.      *  @param base64 the base64 encoded certificate
  80.      *  @param password a password for the certificate if encrypted
  81.      *  @return the PKCS#12 object, or NULL on failure.
  82.      */
  83.     static KSSLPKCS12* fromString(QString base64, QString password = "");
  84.  
  85.     /**
  86.      *  Create a KSSLPKCS12 object by reading a PKCS#12 file.
  87.      *  @param filename the filename of the certificate
  88.      *  @param password a password for the certificate if encrypted
  89.      *  @return the PKCS#12 object, or NULL on failure.
  90.      */
  91.     static KSSLPKCS12* loadCertFile(QString filename, QString password = "");
  92.  
  93.     /**
  94.      *  Convert to a Base64 string.
  95.      *  @return the certificate in base64 form
  96.      */
  97.     QString toString();
  98.  
  99.     /**
  100.      *  Raw set the PKCS12 object.
  101.      *  @param c the openssl PKCS12 object
  102.      *  @internal
  103.      */
  104.     void setCert(PKCS12 *c);
  105.  
  106.     /**
  107.      *  Change the password of the PKCS#12 in memory.
  108.      *  @param pold the old password
  109.      *  @param pnew the new password
  110.      *  @return true on success
  111.      */
  112.     bool changePassword(QString pold, QString pnew);
  113.  
  114.     /**
  115.      *  Get the private key.
  116.      *  @return the internal OpenSSL private key format
  117.      *  @internal
  118.      */
  119.     EVP_PKEY *getPrivateKey();
  120.  
  121.     /**
  122.      *  Get the X.509 certificate.
  123.      *  @return the X.509 certificate for the PKCS#12 object, or NULL
  124.      */
  125.     KSSLCertificate *getCertificate();
  126.  
  127.     /**
  128.      *  Write the PKCS#12 to a file in raw mode.
  129.      *  @param filename the file to write to
  130.      *  @return true on success
  131.      */
  132.     bool toFile(QString filename);
  133.  
  134.     /**
  135.      *  Check the X.509 and private key to make sure they're valid.
  136.      *  @return the result of the validation
  137.      *  @see KSSLCertificate
  138.      */
  139.     KSSLCertificate::KSSLValidation validate();
  140.  
  141.     /**
  142.      *  Check the X.509 and private key to make sure they're valid.
  143.      *  @param p the purpose to validate for
  144.      *  @return the result of the validation
  145.      *  @see KSSLCertificate
  146.      */
  147.     KSSLCertificate::KSSLValidation validate(KSSLCertificate::KSSLPurpose p);
  148.  
  149.     /**
  150.      *  Check the X.509 and private key to make sure they're valid.
  151.      *  Ignore any cached validation result.
  152.      *  @return the result of the validation
  153.      *  @see KSSLCertificate
  154.      */
  155.     KSSLCertificate::KSSLValidation revalidate();
  156.  
  157.     /**
  158.      *  Check the X.509 and private key to make sure they're valid.
  159.      *  Ignore any cached validation result.
  160.      *  @param p the purpose to validate for
  161.      *  @return the result of the validation
  162.      *  @see KSSLCertificate
  163.      */
  164.     KSSLCertificate::KSSLValidation revalidate(KSSLCertificate::KSSLPurpose p);
  165.  
  166.     /**
  167.      *  Check if the X.509 and private key are valid.
  168.      *  @return true if valid
  169.      */
  170.     bool isValid();
  171.  
  172.     /**
  173.      *  Check if the X.509 and private key are valid.
  174.      *  @param p the purpose to validate for
  175.      *  @return true if valid
  176.      */
  177.     bool isValid(KSSLCertificate::KSSLPurpose p);
  178.  
  179. protected:
  180.     KSSLPKCS12();
  181.     bool parse(QString pass);
  182.  
  183. private:
  184.     KSSLPKCS12Private *d;
  185.     PKCS12 *_pkcs;
  186.     KOpenSSLProxy *kossl;
  187.     EVP_PKEY *_pkey;
  188.     KSSLCertificate *_cert;
  189.     STACK_OF(X509) *_caStack;
  190. };
  191.  
  192.  
  193. #endif
  194.  
  195.